import BtnUI from '../core/base/BtnUI';
import ModalUI from '../core/base/ModalUI';


/**
* @param {import("@minecraft/server").Player} player
*/
function showAdminUI(player) {
    const form = new BtnUI(player);

    form.__Title = "管理员菜单";

    form.add_btn('悬浮字', "", function () {
        showFloatingText(player);
    })

    form.show()
}

/**
* @param {import("@minecraft/server").Player} player
*/
function showFloatingText(player) {
    const form = new ModalUI(player)
        .title("设置面板")
        .addInput('floating_text_entity_name', "输入悬浮字")

    form.show((/** @type {{ [x: string]: any; }} */ data) => {
        // 获取输入的字符串
        const floating_text_entity_name = JSON.stringify(data['floating_text_entity_name']);
        // 判断是否为字符串类型
        if (typeof floating_text_entity_name != "string") return;
        // 判断内容是否为空
        if (floating_text_entity_name == '""') return player.sendMessage("内容不能为空");

        // 生成悬浮字实体并获取对象
        const floating_text_entity = player.dimension.spawnEntity("maskviva:floating_text", player.location);

        // 把实体的名称设为去除外部的引号的字符串
        floating_text_entity.nameTag = floating_text_entity_name.slice(1, -1);
    });
}

export {
    showAdminUI,
    showFloatingText
}